#ifndef NPROC_INC
#define NPROC_INC

#ifdef _WIN32
#include <sysinfoapi.h>
#include <windows.h>
#elif defined(__APPLE__)
#define XOPEN_SOURCE 700
#include <unistd.h>
typedef unsigned int u_int;
typedef unsigned char u_char;
typedef unsigned short u_short;
#include <sys/sysctl.h>
#else
#include <unistd.h>
#endif

static int __platform_nproc() {
#ifdef _WIN32
  SYSTEM_INFO si;
  GetSystemInfo(&si);
  return si.dwNumberOfProcessors;
#elif defined(__APPLE__)
  int count;
  size_t count_len = sizeof(count);
  if (sysctlbyname("hw.ncpu", &count, &count_len, NULL, 0) == 0) {
    return count;
  }
  return 1;  // Fallback
#else
  return sysconf(_SC_NPROCESSORS_ONLN);
#endif
}

#endif